<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	isperp.workflow.jumpto = function(processId, pcontrolid) {
		isperp.openDialog({
			contentUrl : "workflow/processRun/jumptoEdit?processId=" + processId + (pcontrolid ? "&pcontrolid=" + pcontrolid : ""),
			width : 660,
			height : 480,
			title : "流程跳转"
		});
	};

	function endProcess(processId) {
		isperp.confirmAlert("您确定要结束此流程？", {
			yes : function() {
				$.post("workflow/processRun/endProcess?processId=" + processId, function(data) {
					isperp.tooltip("流程结束！");
					allProcessListGrid.reload();
				});
			}
		});
	}

	function reOpenProcess(processId) {
		isperp.confirmAlert("您确定要重新开启此流程？", {
			yes : function() {
				$.ajax("workflow/processRun/reOpenProcess?processId=" + processId, function(data) {
					isperp.alert(data);
				});
			}
		});
	}

	function jumpProcess(processId) {

	}

	function tranProcess(processId) {

	}

	function deleteProcess(processId) {

		isperp.confirmAlert("您确定要删除此流程？", {
			yes : function() {
				$.post("workflow/processRun/deleteProcess?processId=" + processId, function(data) {
					isperp.tooltip("流程结束！");
					allProcessListGrid.reload();
				});

			}
		});

	}

	function reOpenProcess(processId) {

		isperp.confirmAlert("您确定要重新开启此流程？", {
			yes : function() {
				$.post("workflow/processRun/reOpenProcess?processId=" + processId, function(data) {
					isperp.tooltip("流程重启开启！");
					allProcessListGrid.reload();
				});

			}
		});

	}

	function processAction(rowObject) {

		var action = "";
		var processKey = rowObject.proc_def_id_.split(":")[0];

		action += isperp.createGridAction({
			title : "流程跟踪",
			iconCls : "icon-preview",
			onclick : "isperp.openDialog({contentUrl:'workflow/processRun/traceView?processId=" + rowObject.proc_inst_id_ + "'})"
		});
		action += isperp.createGridAction({
			title : "查看详细",
			iconCls : "icon-view",
			onclick : "isperp.openDialog({contentUrl:'workflow/processRun/entryProcess?processKey=" + processKey + "&processId=" + rowObject.proc_inst_id_ + "'})"
		});
		if (rowObject.end_time_) {
			action += isperp.createGridAction({
				title : "重新打开流程",
				iconCls : "icon-change",
				onclick : "reOpenProcess('" + rowObject.proc_inst_id_ + "')"
			});
		} else {

			action += isperp.createGridAction({
				title : '转派人员',
				iconCls : 'icon-change',
				onclick : "isperp.workflow.transferAssignee('" + rowObject.proc_inst_id_ + "','allProcessListGrid')"
			});

			action += isperp.createGridAction({
				title : '流程跳转',
				iconCls : 'icon-config',
				onclick : "isperp.workflow.jumpto('" + rowObject.proc_inst_id_ + "','allProcessListGrid')"
			});

			action += isperp.createGridAction({
				title : "终止流程",
				iconCls : "ui-icon-pencil",
				onclick : "endProcess('" + rowObject.proc_inst_id_ + "')"
			});
		}

		return action;
	}
	function allProcessMenuTree_onNodeClick2(event, treeId, treeNode) {

		if (treeNode.id == '1') {
			$("#endTime").attr("op", "isnull")
		} else {

			$("#endTime").attr("op", "isnotnull")
		}
		allProcessMenuTree_onNodeClick(event, treeId, treeNode);
	}

	function allProcessMenuTree_onNodeClickFirst() {
		var nodes = allProcessMenu.zTree.getNodes();
		if (nodes && nodes[0]) {
			node = nodes[0];
		} else {
			return;
		}
		allProcessMenu.zTree.selectNode(node);
		var postData = allProcessListGrid.jqGrid.jqGrid("getGridParam", "postData");
		$.extend(postData, {
			queryPath : node.treenodePath
		});
		allProcessListGrid.search();
	}
</script>
<div class="container_0 clearfix">
	<div class="box no-border">
		 
		<isperp:grid url="workflow/processRun/allProcessList" datatype="local"
			ondbClickRowEvent="" gridId="allProcessListGrid"
			gridTitle="${pageTitle}" cusFormatterActions="true"
			cusDialogSize="big" actionsWidth="160"
			cusActions="processAction(rowObject)" sortname="proc_inst_id_"
			sortorder="desc"
			afterGridCreate="allProcessMenuTree_onNodeClickFirst();">
			<jsp:attribute name="searchbar">
				<input type="hidden" value="0" id="endTime" field="end_time_"
					op="isnull">
				<table class="search-table">
					<tbody>
						<tr>
							<td class="td1">流程定义：</td>
							<td class="td2"><input type="text" field="proc_def_id_"
								op="cn">
							</td>
							<td class="td1">流程id：</td>
							<td class="td2"><input type="text" field="proc_inst_id_"
								op="eq">
							</td>
							<td class="td1">业务表id：</td>
							<td class="td2"><input type="text" field="business_key_"
								op="eq">
							</td>
							
						</tr>
					</tbody>
				</table>
			</jsp:attribute>
			<jsp:attribute name="toolbar">
				<isperp:treeMenu id="allProcessMenu"
					targetGridId="allProcessListGrid"
					nodes="[{id:1,name:'进行中'},{id:2,name:'已结束'}]">
					<isperp:async enable="false"></isperp:async>
					<isperp:data simpleData="true"></isperp:data>
					<isperp:callback onClick="allProcessMenuTree_onNodeClick2">
					</isperp:callback>
				</isperp:treeMenu>
			</jsp:attribute>

			<jsp:body> 
				<isperp:column name="id_" title="id" hidden="true"></isperp:column>
				<isperp:column name="proc_def_id_" title="流程定义" width="100">
				</isperp:column> 
			 	<isperp:column name="proc_inst_id_" title="流程实例" width="60">
				</isperp:column> 
				<isperp:column name="business_key_" title="业务id" width="100">
				</isperp:column> 
				 
				 
				<isperp:column name="start_user_id_" title="发起人" width="60">
				</isperp:column> 
				
				
			
			</jsp:body>
		</isperp:grid>
	</div>


</div>
